package com.holyant.goods.enums;

public enum StatusEnum {
    /**
     * 启用
     */
    ENABLE(0, "启用"),
    /**
     * 停用
     */
    DISABLE(1, "停用");

    private final Integer code;
    private final String name;

    StatusEnum(Integer code, String name)
    {
        this.code = code;
        this.name = name;
    }

    public static StatusEnum ofCode(Integer code) {
        for (StatusEnum value : values()) {
            if (value.code.compareTo(code) == 0) return value;
        }
        throw new RuntimeException("unknown GdsBusinessCategory status code");
    }

    public Integer getCode()
    {
        return code;
    }

    public String getName()
    {
        return name;
    }

    public static String getNameByCode(Integer code) {
        for (StatusEnum item : StatusEnum.values()) {
            if (item.getCode().equals(code)) {
                return item.getName();
            }
        }
        return null;
    }

    public static Integer getCodeByName(String name) {
        for (StatusEnum item : StatusEnum.values()) {
            if (item.getName().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    public static StatusEnum parse(Integer code) {
        for (StatusEnum item : StatusEnum.values()) {
            if (item.getCode().equals(code)) {
                return item;
            }
        }
        return null;
    }

    public static StatusEnum parseByName(String name) {
        for (StatusEnum item : StatusEnum.values()) {
            if (item.getName().equals(name)) {
                return item;
            }
        }
        return null;
    }

    public boolean atStatus(Integer code){
        return this.code.compareTo(code) == 0;
    }
}
